/*
 * author zby
 * 首页初始化数据
 */

(function (document, window, $, Utils) {
    'use strict';
    var pageParams = Utils.getUrlParams();
    var vm = {};
    $(function () {
        var fns = {
            search: function (me) {
                Utils.getSimpleJson({
                    url: "/manager/comment/page",
                    params: Utils.getSearchParams(me),
                    fn: function (data) {
                        vm.comments = data;
                    }
                })
            },
            comment: function () {
                Utils.getSimpleJson({
                    url: "/manager/comment/page",
                    params: {
                        articleId: pageParams.id
                    },
                    fn: function (data) {
                        vm.comments = data;
                    }
                })
            },
            change: function (me) {
                const id = $(me).find("option:selected").val();
                if (id) {
                    vm.article = {
                        id: $(me).find("option:selected").val(),
                        name: $(me).find("option:selected").text()
                    }
                } else {
                    vm.article = {
                        id: "",
                        name: "所有文章"
                    }
                }
            },
            reply: function (cid) {
                Utils.getSimpleJson({
                    url: "/manager/comment/rely/" + cid,
                    fn: function () {
                        layer.msg("恢复成功",{time:1000,icon:2},function () {
                            fns.search();
                        })
                    }
                })
            }
        };
        window.fns = fns;
        init();
    });

    //入口方法
    function init() {
        vm = new Vue({
            el: '#tableInfo',
            data: {
                comments: {},
                article: {},
                articles: {},
                enums: {}
            },
        })
        Utils.getSimpleJson({
            url: "/manager/articleCatalog/" + pageParams.id,
            fn: function (data) {
                vm.article = data;
            }
        })
        Utils.getSimpleJson({
            url: "/manager/articleCatalog/withoutLevel",
            params: {
                flag: false,
            },
            fn: function (data) {
                vm.articles = data;
            }
        })
        Utils.getSimpleJson({
            url: "/core/enum/list",
            noAsync: false,
            params: {
                path: "BooleanEnum,CommentTypeEnum",
            },
            fn: function (data) {
                vm.enums = data;
            }
        })
        fns[pageParams.pageType]();
    }


})(document, window, jQuery, Utils);